from json import dumps
from typing import Any, Dict, List, Literal


class JSONPatch:
    def __init__(self):
        self.patch: List[Dict[str, Any]] = []

    def add_patch(
        self,
        op: Literal["add", "remove", "replace", "move", "copy", "test"],
        path: str,
        value: Any,
    ):
        self.patch.append({"op": op, "path": path, "value": value})
        return self

    def stringify(self) -> str:
        return dumps(self.patch)


class StatusPatch:
    def __init__(self):
        self.status_patch: List[Dict[str, Any]] = []

    def add_patch(self, op: Literal["replace", "add", "remove"], value: int):
        """
        ## 任务状态变更
        - replace: 替换状态 `status = value`
        - add: 添加状态 `status &= value`
        - remove: 移除状态 `status &= ~value`
        """
        self.status_patch.append({"op": op, "value": value})
        return self
